package com.mentaleye.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.bean.RoleBean;
import com.mentaleye.dal.dao.RoleDao;
import com.mentaleye.dal.model.Role;
import com.mentaleye.dal.model.RoleExample;
import com.mentaleye.service.RoleService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.ObjectUtil;
@Service
public class RoleServiceImpl implements RoleService{

	@Autowired
	private RoleDao roleDao;
	@Override
	public boolean editRole(RoleBean roleBean, boolean add) {
		boolean result = false;
		Role role = (Role) ObjectUtil.transfer(roleBean,Role.class);
		if(add){
			result = roleDao.addRole(role);
		}else{
				result = roleDao.updateRole(role);
		}
		return result;
	}

	@Override
	public boolean deleteRoleByList(Integer ids) {
		return roleDao.deleteRole(ids);
	}

	@Override
	public void queryRoleByPage(CommonPage commonPage) {
		@SuppressWarnings("unchecked")
		List<RoleBean> data = ObjectUtil.transferList(roleDao.selectRole(commonPage.pageToMap()),RoleBean.class);
		commonPage.setPageData(data);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<RoleBean> queryAllRole(RoleExample roleExample) {
		return ObjectUtil.transferList(roleDao.selectRoleList(roleExample),RoleBean.class);
	}

	@Override
	public RoleBean queryRoleByNo(Integer roleNo) {
		RoleBean roleBean = (RoleBean) ObjectUtil.transfer(roleDao.selectRoleByNo(roleNo), RoleBean.class);
		return roleBean;
	}

}
